module rank {

    export class ImageNumber extends egret.Sprite {

        private numSpriteSheet: GameSpriteSheet;
        private num: number;

        public static readonly INTERVAL: number = 5;

        public constructor(num: number, numSpriteSheet: GameSpriteSheet) {
            super();
            this.num = num;
            this.numSpriteSheet = numSpriteSheet;
            this.layout();
        }

        public setNb(num: number): void {
            this.num = num;
            this.layout();
        }

        private layout(): void {
            this.removeChildren();
            let nums = this.num.toString().split("");
            let x = 0;
            for (let i = 0; i < nums.length; i++) {
                console.log(nums[i])
                let texture = this.numSpriteSheet.getTexture(nums[i]);
                let bitmap: egret.Bitmap = new egret.Bitmap(texture);
                this.addChild(bitmap);
                bitmap.x = x;
                x += bitmap.width + ImageNumber.INTERVAL;
            }
        }

    }

}